package com.example.testcentral.designpattern

import android.util.Log
import com.example.testcentral.designpattern.ObserverPattern.CurrentConditionsDisplay
import com.example.testcentral.designpattern.ObserverPattern.WeatherData
import com.example.testcentral.designpattern.decoratorpattern.Baverage
import com.example.testcentral.designpattern.decoratorpattern.Espresso
import com.example.testcentral.designpattern.decoratorpattern.HouseBlend
import com.example.testcentral.designpattern.factorypattern.ChicagoCheesePizza
import com.example.testcentral.designpattern.factorypattern.ChicagoPizzaStore
import com.example.testcentral.designpattern.factorypattern.NyPizzaStore

/**
 * File Name: TestRun
 * Author: zhangzhenzhong
 * Created on: 2024/7/8
 * Description:
 */
class TestRun {

    object main{
        @JvmStatic
        fun main(agrs:Array<String>){
            DoubleCheckLockingSingleton.getInstance().doSomething()
            testObserverPattern()
            testDecoratorPattern()
            testFactoryPattern()
        }
    }

    companion object {
        @JvmStatic
        fun testObserverPattern(){

            var weatherData:WeatherData=WeatherData()
            //将观察者传入被观察者，被观察通过传来的值 注册观察者
            CurrentConditionsDisplay(weatherData)
            weatherData.setWeather(10f,30f)
            weatherData.setWeather(11f,31f)
            weatherData.setWeather(12f,32f)
        }


        fun testDecoratorPattern(){
            var baverage:Baverage= Espresso();
            var baverage1:Baverage= HouseBlend();
            Log.d(javaClass.name, "testDecoratorPattern+baverage: ${baverage.description+baverage.cost}")
            Log.d(javaClass.name, "testDecoratorPattern+baverage1: ${baverage1.description+baverage1.cost}")
        }

        fun testFactoryPattern(){
            var nyPizzaStore=NyPizzaStore()
            var chicagoPizzaStore=ChicagoPizzaStore()

            nyPizzaStore.orderPizza("cheese")
            chicagoPizzaStore.orderPizza("cheese")

        }
    }
}